package com.opengw.configuration.config;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.opengw.exception.OpenGWException;
import com.opengw.http.HTTPRequest;
import com.opengw.http.HTTPResponse;

@Entity
@Table(name = "route_config")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class RouteConfig {
	protected long configId;
	protected String configText;
	protected boolean changeRequest;
	protected boolean changeResponse;
	protected boolean controlRequest;
	protected boolean controlResponse;
	
	public RouteConfig(){
		System.out.println("**********CONFIGCONS*********");
	}
	
	public RouteConfig(boolean changeRequest, boolean controlRequest, boolean changeResponse, boolean controlResponse){
		this.changeRequest = changeRequest;
		this.controlRequest = controlRequest;
		this.changeResponse = changeResponse;
		this.controlResponse = controlResponse;
		
	}
	
	public abstract void doChangeRequest(HTTPRequest request) throws OpenGWException;
	
	public abstract void doChangeResponse(HTTPResponse response) throws OpenGWException;
	
	public abstract void doControlRequest(HTTPRequest request) throws OpenGWException;
	
	public abstract void doControlResponse(HTTPResponse response) throws OpenGWException;
	
	public void setConfigId(long configId) {
		this.configId = configId;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "config_id")
	public long getConfigId() {
		return configId;
	}

	public void setChangeResponse(boolean changeResponse) {
		this.changeResponse = changeResponse;
	}

	@Transient
	public boolean isChangeResponse() {
		return changeResponse;
	}

	public void setControlRequest(boolean controlRequest) {
		this.controlRequest = controlRequest;
	}

	@Transient
	public boolean isControlRequest() {
		return controlRequest;
	}

	public void setControlResponse(boolean controlResponse) {
		this.controlResponse = controlResponse;
	}

	@Transient
	public boolean isControlResponse() {
		return controlResponse;
	}

	public void setChangeRequest(boolean changeRequest) {
		this.changeRequest = changeRequest;
	}

	@Transient
	public boolean isChangeRequest() {
		return changeRequest;
	}

	public void setConfigText(String configText) {
		System.out.println("************************************");
		System.out.println("*************" + configText + "*************");
		System.out.println("************************************");
		this.configText = configText;
	}

	@Column(name = "config_text")
	public String getConfigText() {
		return configText;
	}

}
